#!/bin/sh

echo "请选择 svn 的版本："
svnVersionList=(
    "master"
    "master_en"
    "dev"
)
select svnVersion in "${svnVersionList[@]}"
do
    if test -z $svnVersion
    then
        echo "SVN 版本选择错误，请重新选择"
    else
        break
    fi
done

read -r -p "请输入gm_server项目所在的根路径：" gmPath
# -r 如果给出此选项，则反斜杠不会充当转义字符。
if test -d $gmPath
then
    echo ""
else
    echo $gmPath
    echo "gm_server path is not exist."
    exit
fi


tmpSvnJsonDir=svn_json
projectPath=$gmPath/data
jsonSvnPath=$tmpSvnJsonDir/$svnVersion/code/phoenix

if test -d $tmpSvnJsonDir
then
    rm -rf $tmpSvnJsonDir
fi
svn checkout svn://dark.phoenix.wang/phoenix/publish/server/$svnVersion $tmpSvnJsonDir/$svnVersion
if test -d $tmpSvnJsonDir/$svnVersion
then
    echo ""
else
    exit
fi

echo "====== copy file start. ======"
cpFileList=(
    "ArchangelEntrie.json"
    "EffectEntrie.json"
    "EntrieInfo.json"
    "Equip.json"
    "EquipEngrave.json"
    "EquipInjection.json"
    "EquipInjectionProperty.json"
    "EquipPart.json"
    "Fate.json"
    "FateProp.json"
    "FateUnsealProperty.json"
    "Gem.json"
    "Item.json"
    "MagicPet.json"
    "MagicPetSkilllearn.json"
    "Outfit.json"
    "Rune.json"
    "TailsmanEffectEntrie.json"
    "Talisman.json"
    "TalismanBaseProp.json"
    "Wings.json"
    "WingsEntrie.json"
)
for filename in "${cpFileList[@]}"
do
    cp $jsonSvnPath/$filename $projectPath/code_phoenix/$filename
done

if test -d $projectPath/code_phoenix/i18n
then
    echo ""
else
    mkdir -p $projectPath/code_phoenix/i18n
fi
# :TODO cn.json 需要分版本，进行特殊处理
cp $jsonSvnPath/i18n/cn.json $projectPath/code_phoenix/i18n/zh_cn.json

echo "====== copy file finish. ======"

#rm -rf $tmpSvnJsonDir